﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using cbmobile.DAC;
using PQT.API;
using cbmobile.BLC;
using System.Data;
using System.Data.SqlClient;
using PQT.API.Connection;

namespace cbmobile.BLC
{
    public class BLC_GioHang
    {
        SqlConnection cnn = null;
        DBConnection dbCn = new DBConnection("PQT");
        private CBMobileEntities da = null;
        public BLC_GioHang()
        {
            da = new CBMobileEntities();
        }

        public IList<DONHANG> All_Product()
        {
            return da.DONHANGs.ToList();
        }


        public int Max_MADH()
        {
            IList<DONHANG> list = da.DONHANGs.ToList();
            int gt = list.Last().MaDH;
            return gt;
        }

        #region create DonHang
        public void Create_DH(int MaKH, bool TinhTrang, 
                            int PhuongThuc, DateTime NgayMua, 
                            DateTime NgayThanhToan)

        {
            var objGH = new DONHANG();
            //objGH.MaDH = MaDH;
            objGH.MaKH = MaKH;
            objGH.TinhTrang = TinhTrang;
            objGH.PhuongThuc = PhuongThuc;
            objGH.NgayMua = NgayMua;
            objGH.NgayThanhToan = NgayThanhToan;
            da.DONHANGs.AddObject(objGH);
            da.SaveChanges();
        }
        #endregion

        #region create ChiTietDonHang
        //Điện thoại
        public void Create_CTDH_DT(int MaDH ,int MaSP, int SoLuong,
                            decimal Gia, string TenSP, string Mau)
        {
            var objCTGH = new CHITIETHOADON();
            objCTGH.MaDH = MaDH;
            objCTGH.Ma_SP = MaSP;
            objCTGH.Ten_SP = TenSP;
            objCTGH.SoLuong = SoLuong;
            objCTGH.Gia = Gia;
            objCTGH.MauSac = Mau;
            da.CHITIETHOADONs.AddObject(objCTGH);
            da.SaveChanges();
        }

        //Phụ kiện
        public void Create_CTDH_PK(int MaDH,int MaPK,
                            int SoLuong,
                            decimal Gia, string TenSP,string Mau)
        {
            var objCTGH = new CHITIETHOADON();
            objCTGH.MaDH = MaDH;
            objCTGH.MaPK = MaPK;
            objCTGH.Ten_SP = TenSP;
            objCTGH.SoLuong = SoLuong;
            objCTGH.Gia = Gia;
            objCTGH.MauSac = Mau;
            da.CHITIETHOADONs.AddObject(objCTGH);
            da.SaveChanges();
        }

        //Linh kiện
        public void Create_CTDH_LK(int MaDH,
                            int MaLK, int SoLuong,
                            decimal Gia, string TenSP, string Mau)
        {
            var objCTGH = new CHITIETHOADON();
            objCTGH.MaDH = MaDH;
            objCTGH.MaLK = MaLK;
            objCTGH.Ten_SP = TenSP;
            objCTGH.SoLuong = SoLuong;
            objCTGH.Gia = Gia;
            objCTGH.MauSac = Mau;
            da.CHITIETHOADONs.AddObject(objCTGH);
            da.SaveChanges();
        }

        #endregion

    }
}